<?php
App::uses('AppModel', 'Model');
/**
 * Paise Model
 *
 * @property Ciudade $Ciudade
 * @property User $User
 */
class Paise extends AppModel {

public $validate=array(
    'nombre'=>array(
        'notEmpty'=>array(
            'rule'=>array('notEmpty'),
            'message'=>'es obligatorio el nombre'
        )
        ,'limitDuplicates'=>array(
        'rule'=>array('limitDuplicates',1),
        'message'=>'Ya existe el nombre'
    )
    )
    
);

public function limitDuplicates($check, $limit) {
        
           if(!empty($this->data['Paise']['nombre']))
            {
                $nom = $this->data['Paise']['nombre'];
                //debug($nom); die;
                $check['Paise.nombre !='] = $nom;
            }
                
            $existingPromoCount = $this->find('count', array(
                'conditions' => $check,
                'recursive' => -1
            ));
            return $existingPromoCount < $limit;
        
    }
	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Ciudade' => array(
			'className' => 'Ciudade',
			'foreignKey' => 'ciudade_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'paise_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);

}
